package com.net.module.controller;

import com.net.module.entity.Orders;
import com.net.module.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.constraints.NotNull;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author 猿仁
 * @since 2023-03-02
 */
@Controller
@ResponseBody
@RequestMapping("/api/orders")
public class OrdersController {

    @Autowired
    private IOrdersService service;

    @GetMapping("/getById/{id}")
    public Orders getById(@PathVariable("id") Long id) {
        return service.getById(id);
    }

    @PostMapping("/placeAnOrder/{inventoryId}")
    public boolean placeAnOrder(@PathVariable("inventoryId") Long id,@RequestBody @Validated @NotNull(message = "订单对象不能为空") Orders orders) {
        return service.placeAnOrder(id,orders);
    }

}
